package com.chen.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.domain.TurnoverOrder;
import com.chen.dto.R;
import com.chen.service.TurnoverOrderService;
import com.chen.utils.UserUtil;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: chen
 * @Date: 2021/5/19 2:11 PM
 * @Version 1.0
 */
@RestController
@Api(tags = "成交记录控制器")
@RequestMapping("/turnoverOrders")
public class TurnoverOrdersController {

    @Autowired
    private TurnoverOrderService turnoverOrderService;

    @PostMapping
    public R<Page<TurnoverOrder>> list(Page<TurnoverOrder> page, Integer type, String symbol) {
        if ("0".equals(symbol)) {
            symbol = null;
        }
        Page<TurnoverOrder> list = turnoverOrderService.page(page, new LambdaQueryWrapper<TurnoverOrder>()
                .eq(TurnoverOrder::getBuyUserId, UserUtil.getUser())
                .or()
                .eq(TurnoverOrder::getSellUserId, UserUtil.getUser())
                .eq(type != null, TurnoverOrder::getTradeType, type)
                .eq(StringUtils.isNotBlank(symbol), TurnoverOrder::getSymbol, symbol)
                .orderByDesc(TurnoverOrder::getCreated));
        return R.ok(list);
    }
}
